package com.yc.psychologicalconsultant.controller;

import com.yc.psychologicalconsultant.pojo.Result;
import com.yc.psychologicalconsultant.service.PostService;
import com.yc.psychologicalconsultant.utils.PageUtils;
import com.yc.psychologicalconsultant.vo.PostWriteComment;
import com.yc.psychologicalconsultant.vo.PostWriteForm;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
import java.util.Map;
/**
 * @author YC
 * @version 1.0
 */
@RestController
@RequestMapping("/post")
@Slf4j
public class PostController {
    @Resource
    PostService postService;


    @PostMapping("/collect/post")
    public Result collectForPost(@RequestParam Map<String, Object> params) {
        String postId = (String) params.get("postId");
        int count = (Integer) params.get("count");
        postService.collectForPost(postId, count);
        return Result.success("更新评论状态成功");
    }

    @PostMapping("/zan/post")
    public Result zanForPost(@RequestBody Map<String, Object> params) {
        log.info(params.toString());
        System.out.println(params);
        String postId = (String) params.get("postId");
        int count = (Integer) params.get("count");
        postService.zanForPost(postId, count);
        return Result.success("更新评论状态成功");
    }

    @PostMapping("/zan/comment")
    public Result zanForComment(@RequestBody Map<String, Object> params) {
        String commentId = (String) params.get("commentId");
        int count = (Integer) params.get("commentId");
        postService.zanForComment(commentId, count);
        return Result.success("更新评论状态成功");
    }

    // 写一篇帖子
    @PostMapping("/write/post")
    public Result writePost(@RequestBody PostWriteForm postWriteForm) {
        return postService.write(postWriteForm);
    }

    // 写一篇回复
    @PostMapping("/write/comment")
    public Result writeComment(@RequestBody PostWriteComment postWriteComment,@RequestParam Integer recommend) {
        log.info("postWriteComment"+postWriteComment);
        System.out.println(recommend+"    "+postWriteComment);
        return postService.comment(postWriteComment,recommend);
    }

    // 获取帖子所有内容
    @GetMapping("/all/content/{postId}")
    public Result getDetailContent(@PathVariable("postId") String postId) {
        return Result.success(postService.getDetaiContent(postId));
    }

    // 取得所有帖子(分页)
    @GetMapping("/list")
    public Result list(@RequestParam Map<String, Object> params) {
        log.info("查询帖子:"+ Arrays.toString(new Map[]{params}));
        PageUtils page = postService.queryPage(params);
        return Result.success(page);
    }

    @GetMapping("/info")
    public Result info(@RequestParam Map<String, Object> params) {
        PageUtils page = postService.queryInfo(params);
        return Result.success(page);
    }

}
